package com.transaction.util;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created with LXD
 *
 * @author:Luhui
 * @qq:729913162
 * @Date:2018-09-22
 * @Time:12:51
 */
public class ReflectionUtils {

    private static ThreadLocal<Set<Method>> methodSet = new ThreadLocal<Set<Method>>(){
        @Override
        protected Set<Method> initialValue() {
            return new HashSet<>();
        }
    };
    /**
     * 获得该类中的所有方法，包含私有的，包含父类（不包含Object）
     */
    public static Set<Method> getAllMethods(Class<?> clazz){
        Set<Method> methods = methodSet.get();
        if(clazz != Object.class){
            methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
            getAllMethods(clazz.getSuperclass());
        }else{
            methodSet.set(new HashSet<>());
        }
        return methods;
    }
}
